\documentclass[UTF8]{ctexart}
\usepackage{amsmath}
\usepackage{amsthm,amsmath,amssymb}
\usepackage{mathrsfs}
\usepackage{mathrsfs}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{epstopdf}
\usepackage{indentfirst}
\usepackage{caption}
\usepackage{lmodern}
\usepackage{float}
\usepackage{geometry}
\setlength{\parskip}{0.5em}
\geometry{a4paper,scale=0.73}
\pagenumbering{arabic}
% info
\title{AI 第三次作业}
\author{刘本宸 22920202200764}
\date{\today}
\begin{document}
\maketitle
\tableofcontents
\makeatletter %使\section中的内容左对齐
\renewcommand{\section}{\@startsection{section}{1}{0mm}
    {-\baselineskip}{0.5\baselineskip}{\bf\leftline}}
\makeatother
\newpage

\section{解法1：}
\paragraph{根据已知,我们有：}
\begin{equation}
    \begin{split}
        \mathbf{P}(\mathbf X ; \theta) = \prod_{i=1}^n \prod_{j=1}^k \theta_j^{1\{x_i = j\}}
        \\
        \sum_{j=1}^k \theta_j = 1
        \\
        \sum_{i=1}^n n_i = N
        \\
        \mathbf{1}\{x_i = j\} = \left\{
        \begin{aligned}
            0 \quad x_i \neq j \\
            1 \quad x_i = j    \\
        \end{aligned}
        \right
        .
    \end{split}
\end{equation}
\paragraph{两边取对数我们有：}
\begin{equation}
    ln\mathbf P(\mathbf X; \theta) = \sum_{i=1}^n \sum_{j=1}^k ln\theta_j^{1\{x_i = j\}}
    = \sum_{j=1}^k ln\theta_j^{\sum_{i=1}^n 1\{x_i = j\}}
    = \sum_{j=1}^k n_jln\theta_j
\end{equation}
\paragraph{根据最大似然估计的理论，我们要让$\nabla_{\theta}\mathbf{P}(D ;\theta) = 0$, 我们单独拿出来$\theta_j$讨论：}
\begin{equation}
    \frac{\partial ln\mathbf P}{\partial \theta_j} = \partial (n_j \sum_{j=1}^k ln \theta_j) / \partial \theta_j  = 0
\end{equation}
\paragraph{我们运用(1)中第二个式子}，令$\theta_k = 1-\sum_{\substack{j=1}}^{k-1} \theta_ j$， 将此式带入(2)中的最后一项得到
\begin{equation}
    \frac{\partial ln\mathbf P}{\partial \theta_j} = \frac{n_j}{\theta_j} - \frac{n_k}{1-\sum^{k-1}_{i=1}\theta_i} = \frac{n_j}{\theta_j} - \frac{n_k}{\theta_k}=0
\end{equation}
\paragraph{推广之后我们有：}
\begin{equation}
    \frac{n_i}{n_j} = \frac{\theta_i}{\theta_j}( i, j \in [1,k]; i,j \in \mathbf{Z})
\end{equation}
\paragraph{根据等比性质我们有：}
\begin{equation}
    \frac{n_j}{\sum_{i=1}^k n_i} = \frac{\theta_j}{\sum_{i=1}^k \theta_i}
\end{equation}
\paragraph{在叠加已知公式我们可以得到：}
\begin{equation}
    \theta_j = \frac{n_j}{N}  \text{  }( j \in [1,k]; j \in \mathbf{Z})
\end{equation}
\newpage
\section{解法2：}
\paragraph{根据拉格朗日乘数法我们有：}
\begin{equation}
    \mathbf{L}(ln\mathbf p, \lambda) = \sum_{i=1}^n \sum_{j=1}^k ln \theta_j^{1\{x_i = j\}} + \lambda(1-\sum_{j=1}^k \theta_j)
\end{equation}
\paragraph{分别对其变量求导，得到：}
\begin{equation}
    \begin{cases}
        \frac{\partial ln\mathbf P}{\partial \theta_1} = 0
        \\
        \frac{\partial ln\mathbf P}{\partial \theta_2} = 0
        \\
        \ddots
        \\
        \frac{\partial ln\mathbf P}{\partial \theta_k} = 0
        \\
        1-\sum_{j=1}^k \theta_j = 0
    \end{cases}
\end{equation}
\paragraph{之后使用同第一问的做法也可以得到：}
\begin{equation}
    \theta_j = \frac{n_j}{N}\text{ }( j \in [1,k]; j \in \mathbf{Z})
\end{equation}
\end{document}